import Vue from 'vue'
type FnCall = (electron: ElectronAPI) => void
const importFn = require.context('@/components/', true, /\.vue$/)

export function autoImport (app: Vue.App<any>): void {
  for (const key of importFn.keys()) {
    const state = importFn(key).default
    if (state.name) app.component(state.name, state)
  }
}

export function initPlatform (fnCall: FnCall): void {
  if (window.electron) fnCall(window.electron)
}

export function ISCoreRender (fnCall: (electron: any) => void) {
  if (window.require) fnCall(window.require('electron'))
}

export function InjectElectron (app: Vue.App<any>): void {
  app.config.globalProperties.vesion = 'v 1.0.0'
  const isBrowser = window.electron === undefined
  app.config.globalProperties.isBrowser = isBrowser
}
